package com.kcsj.service.user;


import com.kcsj.dao.LoginLogDao;
import com.kcsj.domain.user.LoginLog;
import com.kcsj.util.Condition;
import com.kcsj.util.JdbcHelper;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

/**
 * @author 李鑫元
 * 4th Dec. 2020
 */
public final class LoginLogService {

    private LoginLogDao loginLogDao = LoginLogDao.getInstance();
    private static LoginLogService loginLogService = new LoginLogService();

    public LoginLogService() {
    }

    public static LoginLogService getInstance(){
        return LoginLogService.loginLogService;
    }

    public LoginLog find(Integer id) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        LoginLog loginLog = loginLogDao.find(id, conn);
        JdbcHelper.close(conn);
        return loginLog;
    }

    public Collection<LoginLog> findAll(List<Condition> conditionList) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        Collection<LoginLog> loginLogs = loginLogDao.findAll(conditionList, conn);
        JdbcHelper.close(conn);
        return loginLogs;
    }

    public Collection<LoginLog> findAllByUsername(List<Condition> conditionList) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        Collection<LoginLog> loginLogs = loginLogDao.findAllByUsername(conditionList, conn);
        JdbcHelper.close(conn);
        return loginLogs;
    }

    public boolean add(LoginLog loginLog) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        boolean add = loginLogDao.add(loginLog, conn);
        JdbcHelper.close(conn);
        return add;
    }

}
